package data;

import java.rmi.RemoteException;
import java.util.HashMap;
import java.util.LinkedList;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.xml.bind.annotation.XmlRootElement;
import view.User;

@XmlRootElement
public class Player implements User {

	private Integer	id;
	private String	login;
	private Integer	points;
	private Boolean	connected;
	private LinkedList<Card> hand;
	private HashMap<Integer, Score> scores;
	
	public Player () throws RemoteException {
		super();
	}
	
	public Player (Integer id, String login, Integer points) {
		this.setId(id);
		this.setLogin(login);
		this.setPoints(points);
		this.setHand(new LinkedList<Card>());
	}

	public Player (Integer id, String login, Integer points, Boolean connected) {
		this.setId(id);
		this.setLogin(login);
		this.setPoints(points);
		this.setConnected(connected);
		this.setHand(new LinkedList<Card>());
	}
	
	public Player(String login) {
		this.setId(0);
		this.setLogin(login);
		this.setPoints(0);
		this.setHand(new LinkedList<Card>());
	}
	
	public void mixHand() {
		LinkedList<Card> mixedHand = new LinkedList<Card>();
		while (!this.hand.isEmpty()) {
			int r = 0 + (int)(Math.random() * ((this.hand.size() - 0) + 1));
			Card e = this.hand.remove(r);
			mixedHand.addFirst(e);
		}
		this.hand = mixedHand;
	}
	
	public Integer getId() { return id; }
	public String getLogin() { return login; }
	public Integer getPoints() { return points; }
	public Boolean getConnected() { return connected; }
	public LinkedList<Card> getHand() { return hand; }
	@GET
	@Path("/socres")
	public HashMap<Integer, Score> getScores() { return scores; }
	public Player setId(Integer id) {
		this.id = id;
		return this;
	}
	public Player setLogin(String login) {
		this.login = login;
		return this;
	}
	public Player setPoints(Integer points) {
		this.points = points;
		return this;
	}
	public Player setConnected(Boolean connected) {
		this.connected = connected;
		return this;
	}
	public Player setHand(LinkedList<Card> hand) {
		this.hand = hand;
		return this;
	}
	public Player setScores(HashMap<Integer, Score> scores) {
		this.scores = scores;
		return this;
	}
}
